import React, { Component} from 'react';
import '../../assets/css/carInform.scss';
import {getCarInform,isDisables} from '../../apis/carApi';

export default class CarCheck extends Component {
    state={
        carInform:{ownerId:{}},
    }
    componentDidMount(){
        this.getCarInform()
    }

    //获取信息
    getCarInform=async ()=>{
        try {
            const _id = this.props.location.state.id;
            const data=await getCarInform({_id});
            this.setState({carInform:data})
            console.log(this.state.carInform);
        } catch (error) {
            console.log('error',error);
        }
    }
    //是否禁用
    isDisable=async (_id)=>{
        try {
        this.state.carInform.disable=this.state.carInform.disable==="1"? "0" : "1";
        const data=await isDisables({_id,disable:this.state.carInform.disable});
        this.setState({carInform:data})
        this.getCarInform()
        } catch (error) {
        console.log('error',error);
        }
    }

    render() {
        const {carInform} =this.state
        return (
            <div>
                <div className="content">
                <div className="image">
                <img src={"http://localhost:3008/images/"+carInform.carImg} alt="" />
                </div>
                <div className="right">
                <p>车主：<span>{carInform.ownerId.name}</span></p>
                    <p>车牌号：<span>{carInform.number}</span></p>
                    <p>车辆品牌：<span>{carInform.brand}</span></p>
                    <p>价格/天：<span>{carInform.price}</span>元</p>
                    <p>电话：<span>{carInform.phone}</span></p>
                    <p>车辆状态：<span>{carInform.status}</span></p>
                    <p>信息描述：<span>{carInform.info}</span></p>
                </div>
                </div>
                <button onClick={()=>this.isDisable(carInform._id)} type="button">
                    {carInform.disable==="1" && <span>禁用</span>}
                    {carInform.disable==="0" && <span>已禁用</span>}
                </button>
            </div>
        )
    }
}
